@extends('app')

@section('content')
<ul class="nav nav-tabs">
    <li class="active"><a href="#">列表</a></li>
</ul>
<div class="panel panel-default mt20">
    <div class="table-responsive panel-body">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>编号</th>
              <th>所属文章</th>
              <th>评论内容</th>
              <th>用户</th>
              <th>回复数</th>
              <th>发布时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
          @foreach($result as $res)
            <tr id="news_{{ $res->comment_id }}">
              <td>{{ $res->comment_id }}</td>
              @if( $res->app_table == 'teaches')
              <td> @if(count($res->teaches)>0)<a href="{{ url('/teaches/'.$res->teaches->id)}} ">{{ str_limit($res->teaches->name,20) }} </a>@else 文章已删除 @endif</td>
              @elseif($res->app_table == 'tcompany')
              <td> @if(count($res->teachesc)>0)<a href="{{url('/teaches/company/show/'.$res->teachesc->id)}}">{{ str_limit($res->teachesc->name,20) }}</a>@else 文章已删除 @endif</td>
              @elseif($res->app_table == 'tcourse')
              <td>
                @if(count($res->teachescc)>0)
                  <a href="javascript:void(0)"
                     onclick="toStudyInfo(this,'/teaches/study','{{$res->teachescc->chapter->teaches_id}}','{{empty($authuser)?0:$authuser->id}}','{{csrf_token()}}','{{$res->teachescc->id}}')">
                     {{ str_limit($res->teachescc->name,20) }}
                  </a>
                  <script>
                    function toStudyInfo(id,url,teachesid,islogin,token,contentid){
                      if(islogin == 0){
                        layer.msg('请先登录...',{time:1000});
                        ShowLogin('MyDiv','fade');
                        return false;
                      }else{
                        $(id).attr('onclick','');
                        $.ajax({
                          'url':url,
                          'type':'POST',
                          'data':'teachesid='+teachesid+'&contentid='+contentid+'&_token='+token,
                          error: function(data) {
                            var response = data.responseJSON;
                            $.each(response,function(k,v){
                              errors +="<div>"+v+"</div>";
                            })
                            layer.open({
                              title: '系统提示',
                              content: errors
                            });
                          },
                          success: function(data){
                            if(data.status == 'success'){
                              if(data.redirectUrl.length > 0){
                                var form = $("<form method='post' action='"+data.redirectUrl+"'></form>");
                                var form_content = $("<input type='hidden' name='_token' value='"+token+"'><input type='hidden' name='id' value='"+data.data.id+"'>");
                                form.append(form_content);
                                layer.msg( data.msg,{time: 1000}, function(){
                                  form.appendTo("body").submit();

//							$('input[name=submit_study]').click();
                                });
                              }else{
                                layer.msg(data.msg);
                              }
                            }else{
                              if(data.redirectUrl.length > 0){
                                layer.msg( data.msg,{time: 1000}, function(){
                                  window.location.href=data.redirectUrl;
                                });
                              }else{
                                layer.msg(data.msg);
                              }
                            }
                          },
                        });
                      }

                    }
                  </script>


                @else
                  文章已删除
                @endif
              </td>
              @endif
              <td><a href="javascript:void(0)"  onclick="showComment('{{$res->content}}')">{{ str_limit($res->content,20) }}</a></td>
              <td>{{getUserName($res->user->id)}}</td>
              <td>{{ $res->childComments->count()}}</td>
              <td>{{ $res->updated_at}}</td>
              <td>
                <a href="javascript:void(0);" onclick="del_one('/admin/teaches/comment/delete','{{$res->comment_id}}','{{csrf_token()}}','comment_id')">
                    <i class="glyphicon glyphicon-remove-sign"></i>
                </a>
              </td>
            </tr>
          @endforeach
          </tbody>
        </table>
    </div>
</div>
<div>{!! $result->render() !!} </div>
@endsection

